/*
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-09-24 16:57:18
 * @LastEditTime: 2021-11-17 14:32:46
 * @LastEditors: vai-bowei
 */
/**
  *
  * json转字符串
  */
function stringToJson(data) {
  return JSON.parse(data);
}
/**
*字符串转json
*/
function jsonToString(data) {
  return JSON.stringify(data);
}
/**
*map转换为json
*/
function mapToJson(map) {
  return JSON.stringify(strMapToObj(map));
}
/**
*json转换为map
*/
function jsonToMap(jsonStr) {
  return objToStrMap(JSON.parse(jsonStr));
}

/**
*map转化为对象（map所有键都是字符串，可以将其转换为对象）
*/
function strMapToObj(strMap) {
  let obj = Object.create(null);
  for (let [k, v] of strMap) {
    obj[k] = v;
  }
  return obj;
}

/**
*对象转换为Map
*/
function objToStrMap(obj) {
  let strMap = new Map();
  for (let k of Object.keys(obj)) {
    strMap.set(k, obj[k]);
  }
  return strMap;
}

/**
* 获取转发参数
*/
export function transmitParam(Param,Url,header) {
  
    var JsonParam = Param ? this.mapToJson(this.objToStrMap(Param)) : "";
    var Param = {
        "AppID":"wx51ce905931b338f9",
        "SchoolID":'',
        "Param":JsonParam,
        "Url":Url,
        "UserID":'',
        "headers":header
    } 
    return Param
}

export function transmitParamGet(Url,header) {
  var Param = {
      "AppID":"wx51ce905931b338f9",
      "SchoolID":'S-666',
      "Param":null,
      "Url":Url,
      "UserID":'s012',
      'headers':header
  }
  return Param
}

export function transmitParamPut(Url,header) { 
  var Param = {
      "AppID":"wx51ce905931b338f9",
      "SchoolID":'',
      "Param":{},
      "Url":Url,
      "UserID":'',
      "headers":header
  }
  return Param
}

export default {
    stringToJson: stringToJson,
    jsonToString: jsonToString,
    mapToJson: mapToJson,
    jsonToMap: jsonToMap,
    strMapToObj: strMapToObj,
    objToStrMap: objToStrMap,
    transmitParam: transmitParam,
    transmitParamGet:transmitParamGet,
    transmitParamPut:transmitParamPut,
}